From: Kevin Day Date: Thu, 26 Jun 2014 03:29:51 +0000 (-0500) Subject: Workaround: compilers on some systems seem to be sensitive to the order of arguments X-Git-Tag: 0.4.1 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=5bdaa0b;p=fll Workaround: compilers on some systems seem to be sensitive to the order of arguments As far as I can tell, some systems (in my case, it was on linuxmint, either debian or ubuntu) the compiler interprets the following differently: 1) gcc -lc main.c 2) gcc main.c -lc The should be the same, but they are not for some compilers. This is also not as obvious, some programs or libraries compile while others do not. In my case, I ran the entire compilation of the f_* fl_* and fll_* libraries using the approach from (1). Everything compiled and worked, up until I tried to compile my firewall program. It complained that firewall_main was not found, despite all of the libraries in the path being valid. I had to recompile the entire f_* fl_* and fll_* libraries using (2) for the firewall program to compile. No functional changes were made, simply the order of compile arguments. Therefore, I have implemented an alternative version of the build command, called build_alt. This should be used if you are using a system where (2) is required over (1). --- diff --git a/build/scripts/generate.sh b/build/scripts/generate.sh index 2a6b028..f714b04 100644 --- a/build/scripts/generate.sh +++ b/build/scripts/generate.sh @@ -121,6 +121,16 @@ generate_main(){ generate_operation_build fi + elif [[ $operation == "build_alt" ]] ; then + if [[ -f ${path_build}.built ]] ; then + echo -e "${c_warning}WARNING: this project has already been built.$c_reset" + else + if [[ ! -f ${path_build}.prepared ]] ; then + generate_prepare_build alt + fi + + generate_operation_build alt + fi elif [[ $operation == "clean" ]] ; then generate_operation_clean elif [[ $operation == "fail-multiple" ]] ; then @@ -159,8 +169,9 @@ generate_help(){ echo -e " ${c_notice}Version $version$c_reset" echo echo -e "$c_highlight$system_name$c_reset $c_notice<${c_reset}operation$c_notice>$c_reset" - echo -e " ${c_important}build${c_reset} Build or compile the code" - echo -e " ${c_important}clean${c_reset} Delete all build files" + echo -e " ${c_important}build${c_reset} Build or compile the code" + echo -e " ${c_important}build_alt${c_reset} Build or compile the code (workaround for certain systems)" + echo -e " ${c_important}clean${c_reset} Delete all build files" echo echo -e "${c_highlight}Options:$c_reset" echo -e " -${c_important}h$c_reset, --${c_important}help$c_reset Print this help screen" @@ -226,6 +237,7 @@ generate_load_settings(){ generate_prepare_build(){ local failure= local level=${variables[$(generate_id project_level)]} + local alt=$1 mkdir -vp ${path_build}{includes,programs,libraries,settings} || failure=1 @@ -267,7 +279,9 @@ generate_operation_build(){ local sources_headers=${variables[$(generate_id build_sources_headers)]} local sources_settings=${variables[$(generate_id build_sources_settings)]} local sources= + local sources_alt= local i= + local alt=$1 if [[ $sources_settings != "" ]] ; then for i in $sources_settings ; do @@ -283,12 +297,20 @@ generate_operation_build(){ if [[ $failure == "" && $shared == "yes" ]] ; then if [[ $sources_library != "" ]] ; then - for i in $sources_library ; do - sources="$sources$path_c$i " - done + sources= + sources_alt= + if [[ $alt == "alt" ]] ; then + for i in $sources_library ; do + sources_alt="$sources_alt$path_c$i " + done + else + for i in $sources_library ; do + sources="$sources$path_c$i " + done + fi - echo $compiler $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_library)]} $sources -shared -Wl,-soname,lib$name.so.$major -o ${path_build}libraries/lib$name.so.$major.$minor.$micro - $compiler $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_library)]} $sources -shared -Wl,-soname,lib$name.so.$major -o ${path_build}libraries/lib$name.so.$major.$minor.$micro || failure=1 + echo $compiler $sources_alt $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_library)]} $sources -shared -Wl,-soname,lib$name.so.$major -o ${path_build}libraries/lib$name.so.$major.$minor.$micro + $compiler $sources_alt $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_library)]} $sources -shared -Wl,-soname,lib$name.so.$major -o ${path_build}libraries/lib$name.so.$major.$minor.$micro || failure=1 if [[ $failure == "" ]] ; then ln -vsf lib$name.so.$major.$minor.$micro ${path_build}libraries/lib$name.so.$major || failure=1 @@ -298,31 +320,53 @@ generate_operation_build(){ if [[ $failure == "" && $sources_program != "" ]] ; then sources= - for i in $sources_program ; do - sources="$sources$path_c$i " - done + sources_alt= + if [[ $alt == "alt" ]] ; then + for i in $sources_program ; do + sources_alt="$sources_alt$path_c$i " + done + else + for i in $sources_program ; do + sources="$sources$path_c$i " + done + fi - echo $compiler $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_program)]} $sources -o ${path_build}programs/$name - $compiler $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_program)]} $sources -o ${path_build}programs/$name || failure=1 + echo $compiler $sources_alt $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_program)]} $sources -o ${path_build}programs/$name + $compiler $sources_alt $arguments ${variables[$(generate_id flags_shared)]} ${variables[$(generate_id flags_program)]} $sources -o ${path_build}programs/$name || failure=1 fi elif [[ $failure == "" ]] ; then + sources= + sources_alt= if [[ $sources_library != "" ]] ; then - for i in $sources_library ; do - sources="$sources$path_c$i " - done + if [[ $alt == "alt" ]] ; then + for i in $sources_library ; do + sources_alt="$sources_alt$path_c$i " + done + else + for i in $sources_library ; do + sources="$sources$path_c$i " + done + fi - echo $compiler $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_library)]} $sources -static -o ${path_build}libraries/lib$name.a - $compiler $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_library)]} $sources -static -o ${path_build}libraries/lib$name.a || failure=1 + echo $compiler $sources_alt $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_library)]} $sources -static -o ${path_build}libraries/lib$name.a + $compiler $sources_alt $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_library)]} $sources -static -o ${path_build}libraries/lib$name.a || failure=1 fi if [[ $failure == "" && $sources_program != "" ]] ; then sources= - for i in $sources_program ; do - sources="$sources$path_c$i " - done + sources_alt= + if [[ $alt == "alt" ]] ; then + for i in $sources_program ; do + sources_alt="$sources_alt$path_c$i " + done + else + for i in $sources_library ; do + sources="$sources$path_c$i " + done + fi - echo $compiler $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_program)]} $sources -static -o ${path_build}programs/$name - $compiler $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_program)]} $sources -static -o ${path_build}programs/$name || failure=1 + echo $compiler $sources_alt $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_program)]} $sources -static -o ${path_build}programs/$name + $compiler $sources_alt $arguments ${variables[$(generate_id flags_static)]} ${variables[$(generate_id flags_program)]} $sources -static -o ${path_build}programs/$name || failure=1 fi fi