Allow Java files to support C language pre-compiled commands

Source: Internet
Author: User
Allow Java files to support C language pre-compiled commands

I. Runtime Environment
1. Ubuntu
2. GCC, awk, and sed must be installed in Ubuntu (currently supported by all servers)
Ii. installation environment
1. Place the script gcc2java. Sh in the project directory. For example:./gcc2javateset/gcc2java. Sh
2. Create a folder include under the project directory and put the C Language header file under the include directory. Ratio
For example:./gcc2javateset/include

Iii. GCC File
1. Overview: the GCC file is an extension of a Java file. In the GCC file, you can use C language precompiled commands and
To use the Java programming language.
2. format:
The first line: <? GCC version = "1.0" encoding = "UTF-8"?> Mark this file as a GCC File
Note: The first line must have this identifier and "<?" No leading space is allowed.
For example:

4. Compile
1. If we do not need to use the GCC file for compilation, the compilation steps are the same as before.
2. If we want to involve the GCC file in compilation, the steps are as follows:
A. Execute the script gcc2java. Sh. Purpose: Convert the GCC file to the Java file we need
Note: When we want to convert the GCC file in a specific file named GCC, we execute: gcc2java. Sh folder path.
B. Overwrite. \ out \ Src in the project. All converted files are in. \ out
C. start compiling the project

V. gcc2java. Sh source code

#! /Bin/sh #11-12-03 to Java support ccheckcommand () {if [$1-EQ 0]; Then ECHO $2 else echo "..... fail .... "Exit fi} gcc2java () {Echo "*********************************** * ***** "Echo "********************************* * ****** "Echo" ******** XXX. GCC ----> XXX. java ********* "Echo" ***** help: gcc2java. sh dirpath ***** "Echo" ***** V1.0 Author: mingli Date: 11.12.04 * "Echo "******************************* * ******** "Echo "***************************** * ******** "Echo" Please wait for a few minutes .......... "Echo Rm-RF out mkdir out/temp CP-RF $1. /out/# determine whether the copy is successful checkcommand $? $1 dir = $ (echo $1 | awk-F/'{print $ NF}') echo $ dir if [-Z $ dir]; then dir = $ (echo $1 | awk-F/'{print $ (NF-1)}') echo $ dir fi chmod + WXR-R. /out/for file in $ (find. /out/$ Dir-name "*. GCC ") Do echo $ file # echo $ {file %. *}. TMP gcc-X c-e-c-W $ file-I. /include >$ {file %. *}. tmp cp-RF $ {file %. *}. TMP. /out/temp # delete from the first row to <? GCC?> Row sed-E 1, 'sed-n'/^ <? GCC */= '$ {file %. *}. TMP 'd $ {file %. *}. TMP >$ {file %. *}. tmp0 # Delete the "# XXX" sed '/^ # [0-9] \ {1, \} \ "*/'d $ {file %. *}. tmp0 >$ {file %. *}. java Rm-RF $ {file %. *}. TMP * done # Check whether the program runs successfully checkcommand $? Success} if [$ #-EQ 0]; then gcc2java. /srcelif [$ #-EQ 1]; then gcc2java $1 else echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! "Echo "!! Please input the true parameters !! "Echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Fi

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.